//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.workflow;

import com.aidong.cache.NameItem;
import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.WorkflowTypeDao;
import com.aidong.model.wills.WorkflowList;
import com.aidong.web.controller.workflow.WorkflowController;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"workflowAudit1"})
public class WorkflowAudit1Controller extends WorkflowController {
    @Resource
    WorkflowTypeDao workflowTypeDao;

    public WorkflowAudit1Controller() {
    }

    @RequestMapping({"list"})
    public ModelAndView list(@RequestParam(value = "category",required = false) String category) {
        return (new ModelAndView("workflow/audit/list")).addObject("workflowType", this.getTypeList("workflowType")).addObject("workflowStatus", this.getTypeList("workflowStatus")).addObject("category", category).addObject("stat", Integer.valueOf(1));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "typeId",required = false) String typeId, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "category",required = false) String category, @RequestParam(value = "name",required = false) String name, @RequestParam(value = "dateType",required = false) String dateType, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "shopCode", shopCode);
        cd.eq("typeId", typeId);
        cd.eq("status", Integer.valueOf(1));
        cd.eq("procResult1", Integer.valueOf(0));
        if(!this.chkNull(category)) {
            ArrayList mv = new ArrayList();
            List ls = this.cache.getItemList("workflowType");
            Iterator i$ = ls.iterator();

            while(i$.hasNext()) {
                NameItem t = (NameItem)i$.next();
                if(category.equals(t.getProp())) {
                    mv.add(t.getId());
                }
            }

            cd.in("typeId", mv.toArray());
        } else {
            cd.ne("typeId", Integer.valueOf(35));
        }

        if(!this.chkNull(name)) {
            ConditionMap mv1 = new ConditionMap(1);
            mv1.like("contractCode", "%" + name + "%");
            mv1.like("memberCode", "%" + name + "%");
            mv1.like("memberName", "%" + name + "%");
            cd.addSub(mv1);
        }

        if(!this.chkNull(dateFrom)) {
            cd.ge("submitTime", this.parseDate(dateFrom, "yyyy-MM-dd"));
        }

        if(!this.chkNull(dateTo)) {
            cd.le("submitTime", this.parseDate(dateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
        }

        this.workflowListDao.queryPageList(pg, cd, (new OrderSet()).desc("submitTime"));
        ModelAndView mv2 = new ModelAndView("workflow/audit/_list");
        mv2.addObject("list", pg.getResultList());
        mv2.addObject("pg", pg);
        return mv2;
    }

    @RequestMapping({"audit"})
    public ModelAndView audit(@RequestParam("id") int id) {
        WorkflowList workflow = (WorkflowList)this.workflowListDao.getById(Integer.valueOf(id));
        if(workflow != null && workflow.getStatus().intValue() == 1) {
            ModelAndView mv = new ModelAndView("workflow/audit/audit");
            mv.addObject("workflow", workflow);
            return mv;
        } else {
            return this.showAlert("没有这个申请!");
        }
    }

    @RequestMapping({"_audit"})
    @ResponseBody
    public String _audit(@RequestParam("id") int id, @RequestParam("result") String result, @RequestParam(value = "note",required = false) String note) {
        WorkflowList workflow = (WorkflowList)this.workflowListDao.getById(Integer.valueOf(id));
        if(workflow != null && workflow.getStatus().intValue() == 1) {
            if(!"1".equals(result) && !"2".equals(result)) {
                return this.getResult(false, "审批结果错误!");
            } else {
                try {
                    this.workflowListDao.updateProcResult(workflow.getWorkflowId().intValue(), workflow.getStatus().intValue(), "1".equals(result), note, this.getLoginUserCode());
                    this.addUserLog("初审" + this.cache.getValue("workflowType", workflow.getTypeId()), "编号:" + workflow.getWorkflowId() + (!this.chkNull(workflow.getContractCode())?",合同号:" + workflow.getContractCode():",会员号:" + workflow.getMemberCode()));
                } catch (Exception var6) {
                    this.log.error("audit workflow", var6);
                    return this.getResult(false, "审批发生错误");
                }

                return this.getResult(true, "审批完成");
            }
        } else {
            return this.getResult(false, "没有这个申请!");
        }
    }
}
